﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml.Serialization;

namespace IceDog.WebService
{
    /// <summary>
    /// WeatherService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WeatherService : System.Web.Services.WebService
    {

        [WebMethod]
        public GetWeatherResponse GetWeather(GetWeatherRequest req)
        {
            var res = new GetWeatherResponse();
            var r = new Random();
            int celsius = r.Next(-20, 50);
            if (req.TemperatureType==TemperatureType.Celsius)
            {
                res.Temperature = celsius;
            }
            else
            {
                res.Temperature = (212 - 32) / 100 * celsius + 32;
            }
            if (req.City.Equals("Redmond"))//micorsoft 总部 Redmond washington
            {
                res.TemperatureCondition = TemperatureCondition.Rainy;
            }
            else
            {
                res.TemperatureCondition = (TemperatureCondition)r.Next(0, 3);
            }
            return res;
        }
    }
    public enum TemperatureType
    {
        Fahrenheit,
        Celsius
    }
    public enum TemperatureCondition
    {
        Rainy,
        Sunny,
        Cloudy,
        Thunderstorm
    }
    [Serializable]
    public class GetWeatherRequest
    {
        public string City { get; set; }
        public TemperatureType TemperatureType { get; set; }
        [XmlIgnore]
        private bool isReal = false;
    }
    [Serializable]
    public class GetWeatherResponse
    {
        public TemperatureCondition TemperatureCondition { get; set; }
        public int Temperature{ get; set; }
    }
}
